<?php
namespace Admin\Controller;
use Think\Controller;
class CateController extends CommonController {
    public function lst(){
      $cate=D('Cate');
      // $cateinfo=$cate->order('id desc')->select();
      $cateinfo=$cate->order('sort desc')->select();
      // var_dump($cateinfo);
      $this->assign('cateinfo',$cateinfo);
      $this->display();
    }
    public function add(){
      $cate=D('Cate');
      if(IS_POST){
        $data['catename']=I('title');
        if($cate->create($data)){
          $cate->add();
          $this->success('添加成功',U('admin/cate/lst'));
        }else{
          $this->error($cate->getError());
        }

      }
      $this->display();
    }
    public function del(){
      $cate=D('Cate');
      if($cate->where('id='.I('get.id'))->delete()){
        $this->success('删除成功',U('admin/cate/lst'));
      }
      // echo I('get.id');
    }
    public function edit(){
      $cate=D('Cate');
      $cateedit=$cate->find(I('get.id'));
      var_dump($cateedit);
      $this->assign('edit',$cateedit);
      if(IS_POST){
        $data['id']=I('id');
        $data['catename']=I('title');
        if($cate->create($data)){
          if($cate->save()){
            $this->success('修改成功',U('admin/cate/lst'));
          }else {
            $this->error('修改错误',U('Admin/cate/edit'));
          }
        }else{
          $this->error($cate->getError());
        }
      }
      $this->display();
    }
  }
 ?>
